package com.fla.millioner.ui;

public class HelpUtils {
    public static class AnswerModel {
        boolean isCorrect;
        boolean isVisible;
        String answerText;

        public AnswerModel(boolean isCorrect, boolean isVisible, String answerText) {
            this.isCorrect = isCorrect;
            this.isVisible = isVisible;
            this.answerText = answerText;
        }
    }
    
    public static int[] calculatePercents(int level, AnswerModel[] answerModels) {
        int[] percents = new int[answerModels.length];

        int visibleCount = 0;
        for (AnswerModel answerModel : answerModels) {
            visibleCount += answerModel.isVisible ? 1 : 0;
        }

        int correctPercent = Math.min((int) (10d / visibleCount * 10 * Math.random()) + Math.max(9 - level, 3) * 10, 90);

        int commonSum = 100 - correctPercent;
        double average = commonSum / (double) (visibleCount - 1);
        for (int i = 0; i < answerModels.length; i++) {
            if (!answerModels[i].isVisible) {
                percents[i] = 0;
                continue;
            }
            if (answerModels[i].isCorrect) {
                percents[i] = correctPercent;
            }
            else {
                percents[i] = (int) (average * Math.random());
                commonSum -= percents[i];
            }
        }

        int newAverage = commonSum / (visibleCount - 1);
        for (int i = 0; i < answerModels.length; i++) {
            if (answerModels[i].isVisible && !answerModels[i].isCorrect) {
                percents[i] += newAverage;
            }
        }

        return percents;
    }
}
